package com.xieyx.licenseplatedemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.xieyx.licenseplate.ElectricLicensePlateTextView;
import com.xieyx.licenseplate.LicensePlateDialogListener;
import com.xieyx.licenseplate.LicensePlateTextView;

public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup rgType;

    private LicensePlateTextView licensePlateTextView;

    private ElectricLicensePlateTextView electricLicensePlateTextView;

    private int type = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        rgType = findViewById(R.id.rg_type);
        licensePlateTextView = findViewById(R.id.plateView);
        electricLicensePlateTextView = findViewById(R.id.electricPlateView);
        rgType.setOnCheckedChangeListener(this);
        findViewById(R.id.textView).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(type == 1){
                    Toast.makeText(MainActivity.this,electricLicensePlateTextView.getPlateText(),Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(MainActivity.this,licensePlateTextView.getPlateText(),Toast.LENGTH_SHORT).show();
                }
            }
        });
        electricLicensePlateTextView.setLicensePlateDialogListener(new LicensePlateDialogListener() {
            @Override
            public void onLicensePlateDialogShow() {
//                Toast.makeText(MainActivity.this,"show",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onLicensePlateDialogHide() {
//                Toast.makeText(MainActivity.this,"hide",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i){
            case R.id.rb_1:
                type = 1;
                licensePlateTextView.setVisibility(View.GONE);
                electricLicensePlateTextView.setVisibility(View.VISIBLE);
                licensePlateTextView.cleatText();
                break;

            case R.id.rb_2:
                type = 2;
                licensePlateTextView.setVisibility(View.VISIBLE);
                licensePlateTextView.setPlateTo7();
                electricLicensePlateTextView.setVisibility(View.GONE);
                electricLicensePlateTextView.cleatText();
                break;

            case R.id.rb_3:
                type  = 3;
                licensePlateTextView.setVisibility(View.VISIBLE);
                licensePlateTextView.setPlateTo8();
                electricLicensePlateTextView.setVisibility(View.GONE);
                electricLicensePlateTextView.cleatText();
                break;
        }
    }
}
